/**
 * 初始化
 * @param self
 * @param tiyData
 */
// import {def} from "vue/src/core/util/lang";

export const init = (tiyData) => {
  tiyData.tData.couponDefineList.splice(0, tiyData.tData.couponDefineList.length);
  tiyData.tParam.selectedCouponDefines.splice(0, tiyData.tParam.selectedCouponDefines.length);
  tiyData.tStatus.modalDistribute.isShow = false;
};

/**
 * 查询VIP优惠券模版列表
 * @param self
 * @param tiyData
 */
export const getVipDefines = (self, tiyData) => {
  self.$Spin.show();
  self.$apiCoupon.getCouponModelList({
    "validityPeriodType":2, //查询当月有效的优惠券模版
    "pageNum":0,
    "pageSize":20
  }).then(function (response){
    tiyData.tData.couponDefineList.splice(0, tiyData.tData.couponDefineList.length);
    self.$Spin.hide();
    if (response.success) {
      let couponPage = response.result;
      couponPage.list.forEach(
        function (item) {
          tiyData.tData.couponDefineList.push(item);
          if (item.state !== 0) {
            item._disabled = true;
          }
        }
      );
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

/**
 * 发放vip月度优惠券
 * @param self
 * @param tiyData
 */
export const distributeMonthCoupons = (self,tiyData,id) => {
  self.$Spin.show();
  // let defines = tiyData.tParam.selectedCouponDefines;
  let defineIds = tiyData.tParam.selectedCouponIds;
  console.log(defineIds);
  // defines.forEach(function(item){
  //   defineIds.push(item.id);
  // });
  self.$apiCoupon.distributeMonthCouponToVips(defineIds).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tStatus.modalDistribute.isShow = false;
      self.$Message.success("发放"+response.result +"张优惠券");
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};
